using System;
using System.Collections.Generic;
using System.Text;

namespace Northwind.NET.Utilities
{
    /// <summary>
    /// Runtime assert
    /// </summary>
    public class RunTimeAssert
    {
        /// <summary>
        /// Throws <see cref="AssertionException"/> if <paramref name="condition"/> is not True
        /// </summary>
        /// <param name="condition">Condition to check</param>
        /// <param name="message">text of the message to use while tjrowing exception of condition is not true</param>
        public static void True(bool condition, string message)
        {
            if (!condition) throw new AssertionException(message);
        }
        /// <summary>
        /// Throws <see cref="AssertionException"/> if <paramref name="objectToCheckForNull"/> is null
        /// </summary>
        /// <param name="objectToCheckForNull">Object instance to check for null value</param>
        public static void NotNull(object objectToCheckForNull)
        {
            //ss:if (o == null) throw new NullReferenceException();
            if (objectToCheckForNull == null) throw new AssertionException("Object reference not set to an instance of an object.");
        }
        /// <summary>
        /// Throws <see cref="AssertionException"/> if <paramref name="objectToCheckForNull"/> is null
        /// </summary>
        /// <param name="objectToCheckForNull">Object instance to check for null value</param>
        /// <param name="message">Exception message</param>
        public static void NotNull(object objectToCheckForNull, string message)
        {
            //ss:if (o == null) throw new NullReferenceException();
            if (objectToCheckForNull == null) throw new AssertionException(message);
        }
        
        /// <summary>
        /// Throws <see cref="NullOrEmptyStringException"/> if <paramref name="stringToCheckForNull"/> 
        /// is null or empty
        /// </summary>
        /// <param name="stringToCheckForNull">String to check for null value or empty value</param>
        public static void NotNullOrEmptyString(string stringToCheckForNull)
        {
            if (stringToCheckForNull == null || stringToCheckForNull.Length == 0) throw new NullOrEmptyStringException("Null or empty string");
        }
        /// <summary>
        /// Throws <see cref="UnreachableCodeException"/>
        /// </summary>
        /// <param name="message">Message text to use with thrown <see cref="UnreachableCodeException"/> </param>
        public static void CantReach(string message)
        {
            throw new UnreachableCodeException(message);
        }

        /// <summary>
        /// Throws <see cref="UnreachableCodeException"/>
        /// </summary>
        /// <param name="message">Message text to use with thrown <see cref="UnreachableCodeException"/> </param>
        /// <param name="e">Exception instance</param>
        public static void ImpossibleException(Exception e, string message)
        {
            throw new UnreachableCodeException(e, message);
        }
        /// <summary>
        /// Throws <see cref="AssertionException"/> if file specified in <paramref name="fullPath"/> 
        /// does not exist
        /// </summary>
        /// <param name="fullPath">File fullpath to text existense of</param>
        public static void FileExists(string fullPath)
        {
            if (!System.IO.File.Exists(fullPath))
                throw new AssertionException(string.Format("File doesn't exists {0}",fullPath));
        }
        /// <summary>
        /// Throws <see cref="AssertionException"/> if folder specified in <paramref name="FolderExists"/> 
        /// does not exist
        /// </summary>
        /// <param name="folderFullPath">Folder fullpath to text existense of</param>
        public static void FolderExists(string folderFullPath)
        {
            if (!System.IO.Directory.Exists(folderFullPath))
                throw new AssertionException(string.Format("Folder doesn't exists {0}", folderFullPath));
        }
    }
}
